/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.edu.vttu.phong;

import com.sun.corba.se.spi.orbutil.fsm.Guard;
import java.awt.Color;
import java.awt.Component;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.sql.Connection;
import java.sql.DriverManager;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import vn.edu.vttu.readxml.ReadXML;
import net.proteanit.sql.DbUtils;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import vn.edu.vttu.dichvu.QuanLy_DichVu;
import vn.edu.vttu.model.DichVu;
import vn.edu.vttu.model.KhachHang;
import vn.edu.vttu.model.Loaiphong;
import vn.edu.vttu.readxml.thongtindb;
import vn.edu.vttu.taikhoan.dangNhap;

/**
 *
 * @author KhanhIT
 */
public class Phong_Quanly extends javax.swing.JFrame {
    // String bang[] = new String[];    

    class ItemRenderer extends BasicComboBoxRenderer {

        public Component getListCellRendererComponent(
                JList list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);

            if (value != null) {
                DichVu item = (DichVu) value;
                // đây là thông tin ta sẽ hiển thị , đối bảng khác sẽ khác cột chúng ta sẽ đổi lại tên tương ứng
                setText(item.getTendv().toUpperCase());
            }

            if (index == -1) {
                DichVu item = (DichVu) value;
                setText("" + item.getTendv());
            }

            return this;
        }
    }

    class ItemLoaiphong extends BasicComboBoxRenderer {

        public Component getListCellRendererComponent(
                JList list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);

            if (value != null) {
                Loaiphong item = (Loaiphong) value;
                // đây là thông tin ta sẽ hiển thị , đối bảng khác sẽ khác cột chúng ta sẽ đổi lại tên tương ứng
                setText(item.getTendv());
            }
            if (index == -1) {
                Loaiphong item = (Loaiphong) value;
                setText("" + item.getTendv());
            }
            return this;
        }
    }
    ReadXML read1 = new ReadXML();

    class CustomRenderer extends DefaultTableCellRenderer {

        private static final long serialVersionUID = 6703872492730589499L;

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            TableModel model2;
            try {
                Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                model2 = common.LoadDanhSachPhongDaThue();
                int n = model2.getRowCount();
                String[] bang2 = new String[n];
                for (int i = 0; i < n; i++) {
                    bang2[i] = model2.getValueAt(i, 0).toString();
                }
                for (int i = 0; i < cot; i++) {
                    if (table.getValueAt(row, column).equals(bang2[i])) {
                        cellComponent.setBackground(Color.GREEN);
                        break;
                    } else {
                        cellComponent.setBackground(Color.lightGray);
                    }
                }

            } catch (Exception e) {
            }
            return cellComponent;
        }
    }

    /**
     * Creates new form
     */
    private boolean themdv = false;
    private int id_phong;
    private int id;

    public Phong_Quanly() {
        initComponents();
        enableButton(false);
        setLocation(35, 0);
        fillkhCombo();
    }

    private void fillComboboxLoaiphong() {
        Vector<Loaiphong> model2 = new Vector<Loaiphong>();  // khai báo vector đón dữ liệu từ server rả về
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            model2 = common.loadLoaiphong();
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(rootPane, "Kết nối Server thất bại ");
        }
        if (model2 != null) {
            DefaultComboBoxModel defaultComboBoxMode2 = new javax.swing.DefaultComboBoxModel(model2);//model là  Vector<ParentRole> model = new Vector<ParentRole>();
            cbbLoaiphong.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
            cbbLoaiphong.setModel(defaultComboBoxMode2);
            cbbLoaiphong.setRenderer(new Phong_Quanly.ItemLoaiphong());
        }

    }

    private void fillkhCombo() {
        Vector<DichVu> model = new Vector<DichVu>();  // khai báo vector đón dữ liệu từ server rả về
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            model = common.selectDichVu();

        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(rootPane, "Kết nối Server thất bại ");
        }

        DefaultComboBoxModel defaultComboBoxModel1 = new javax.swing.DefaultComboBoxModel(model);//model là  Vector<ParentRole> model = new Vector<ParentRole>();
        cobTenDV.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
        cobTenDV.setModel(defaultComboBoxModel1);
        cobTenDV.setRenderer(new Phong_Quanly.ItemRenderer());  // chúng ta gỏ giống vậy
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtTenphong = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtMaphong = new javax.swing.JTextField();
        txtGiaphong = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtDonvitinh = new javax.swing.JTextField();
        txtVitri = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cbbLoaiphong = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPhong = new javax.swing.JTable();
        btnXoa = new javax.swing.JButton();
        btnThem = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnLuu = new javax.swing.JButton();
        btnHuy = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblDichVu = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        lbSDT = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        btnThemDV = new javax.swing.JButton();
        btnXoaDV = new javax.swing.JButton();
        btnSuaDV = new javax.swing.JButton();
        lbHoTen = new javax.swing.JLabel();
        btnNhanPhong = new javax.swing.JButton();
        btnLuuDV = new javax.swing.JButton();
        txtSoLuong = new javax.swing.JTextField();
        cobTenDV = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        lbNgayNhan = new javax.swing.JLabel();
        lbNgayTra = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        lbTienDV = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        lbTienPhong = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        lbThanhTien = new javax.swing.JLabel();
        btnXuatHoaDon = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Quản lý phòng");
        setBackground(java.awt.Color.white);
        setName("Quanlyphong"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                Loading(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("QUẢN LÝ PHÒNG KHÁCH SẠN");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông Tin Phòng"));

        jLabel3.setText("Tên phòng:");

        jLabel7.setText("Đơn vị tính:");

        txtMaphong.setEnabled(false);
        txtMaphong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMaphongActionPerformed(evt);
            }
        });

        txtGiaphong.setEnabled(false);

        jLabel2.setText("Mã phòng:");

        txtDonvitinh.setText("ngày");
        txtDonvitinh.setEnabled(false);

        jLabel5.setText("Loại phòng:");

        cbbLoaiphong.setEnabled(false);

        jLabel6.setText("Giá phòng:");

        jLabel4.setText("Vị trí:");

        tblPhong.setBorder(new javax.swing.border.MatteBorder(null));
        tblPhong.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tblPhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblPhong.setCellSelectionEnabled(true);
        tblPhong.setEditingRow(1);
        tblPhong.setRowHeight(50);
        tblPhong.setRowMargin(0);
        tblPhong.setTableHeader(null);
        tblPhong.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblPhongMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                Clickbang(evt);
            }
        });
        jScrollPane1.setViewportView(tblPhong);

        btnXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/trash-icon.png"))); // NOI18N
        btnXoa.setText("Xóa");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/user-add-icon.png"))); // NOI18N
        btnThem.setText("Thêm");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/edit-icon.png"))); // NOI18N
        btnSua.setText("Sửa");
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnLuu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/Save-icon.png"))); // NOI18N
        btnLuu.setText("Lưu");
        btnLuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLuuActionPerformed(evt);
            }
        });

        btnHuy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/Button-Refresh-icon.png"))); // NOI18N
        btnHuy.setText("Reload");
        btnHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHuyActionPerformed(evt);
            }
        });

        jPanel4.setBackground(java.awt.Color.green);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 36, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 31, Short.MAX_VALUE)
        );

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setText("Phòng Đã Cho Thuê");

        jPanel5.setBackground(java.awt.Color.lightGray);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 35, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 31, Short.MAX_VALUE)
        );

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel13.setText("Phòng Trống");

        jButton2.setText("+");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(cbbLoaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtMaphong, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtGiaphong, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTenphong, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel4)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtVitri, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDonvitinh, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnThem)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSua)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnXoa)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLuu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnHuy)))
                .addGap(0, 21, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE)
                        .addGap(13, 13, 13))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtMaphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtTenphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtVitri, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel6)
                        .addComponent(txtGiaphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cbbLoaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton2))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(txtDonvitinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnSua)
                    .addComponent(btnXoa)
                    .addComponent(btnLuu)
                    .addComponent(btnHuy))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addGap(80, 80, 80))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông Tin Dịch Vụ Khách Hàng Thuê Phòng"));

        tblDichVu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblDichVu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblDichVuMousePressed(evt);
            }
        });
        jScrollPane2.setViewportView(tblDichVu);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Tên Khách Hàng: ");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("SĐT:");

        lbSDT.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lbSDT.setForeground(new java.awt.Color(204, 0, 0));

        jLabel12.setText("Tên DV:");

        jLabel14.setText("Số Lượng");

        btnThemDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/Bookmark-add-icon.png"))); // NOI18N
        btnThemDV.setToolTipText("Thêm dịch vụ vào hóa đơn cho khách hàng");
        btnThemDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemDVActionPerformed(evt);
            }
        });

        btnXoaDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/Places-trash-full-icon.png"))); // NOI18N
        btnXoaDV.setToolTipText("Xóa dịch vụ ra khỏi hóa đơn cho khách hàng");
        btnXoaDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaDVActionPerformed(evt);
            }
        });

        btnSuaDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/edit-validated-icon.png"))); // NOI18N
        btnSuaDV.setToolTipText("Sửa Thông Tin Dịch Vụ Khách Hàng Sử Dụng");
        btnSuaDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaDVActionPerformed(evt);
            }
        });

        lbHoTen.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lbHoTen.setForeground(new java.awt.Color(204, 0, 0));

        btnNhanPhong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/process-accept-icon.png"))); // NOI18N
        btnNhanPhong.setToolTipText("Click Nhận phòng cho khách hàng");
        btnNhanPhong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNhanPhongActionPerformed(evt);
            }
        });

        btnLuuDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vn/edu/vttu/img/Floppy-Small-icon.png"))); // NOI18N
        btnLuuDV.setToolTipText("Lưu lại thông tin dịch vụ mà khách hàng sử dụng");
        btnLuuDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLuuDVActionPerformed(evt);
            }
        });

        txtSoLuong.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSoLuongKeyTyped(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Ngày Nhận");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel15.setText("Ngày Trả");

        lbNgayNhan.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        lbNgayTra.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lbNgayTra.setText("ngaytra");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông Tin Thanh Toán"));

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(0, 0, 255));
        jLabel16.setText("Tiền Dịch Vụ: ");

        lbTienDV.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTienDV.setForeground(new java.awt.Color(0, 0, 255));
        lbTienDV.setText("tiendv");

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(0, 0, 255));
        jLabel17.setText("Tiền phòng");

        lbTienPhong.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTienPhong.setForeground(new java.awt.Color(0, 0, 255));
        lbTienPhong.setText("tienphong");

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel18.setForeground(new java.awt.Color(255, 0, 51));
        jLabel18.setText("Tổng Tiền: ");

        lbThanhTien.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        lbThanhTien.setForeground(new java.awt.Color(255, 0, 51));
        lbThanhTien.setText("thanhtien");

        btnXuatHoaDon.setText("Xuất Hóa Đơn");
        btnXuatHoaDon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXuatHoaDonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lbTienDV, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lbTienPhong, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbThanhTien, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnXuatHoaDon)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(lbTienDV))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(lbTienPhong))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(lbThanhTien))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnXuatHoaDon))
        );

        jButton1.setText("+");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(btnNhanPhong)
                                .addGap(10, 10, 10)
                                .addComponent(btnThemDV)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnXoaDV)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSuaDV)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnLuuDV))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lbNgayNhan))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cobTenDV, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(127, 127, 127)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel15)
                                            .addComponent(jLabel10))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lbSDT)
                                            .addComponent(lbNgayTra)))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addComponent(jButton1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel14)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lbHoTen))
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 51, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(lbHoTen))
                        .addComponent(lbSDT, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(lbNgayNhan)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(lbNgayTra))))
                .addGap(3, 3, 3)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(cobTenDV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(txtSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThemDV)
                    .addComponent(btnXoaDV)
                    .addComponent(btnSuaDV)
                    .addComponent(btnNhanPhong)
                    .addComponent(btnLuuDV))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(49, 49, 49))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(507, 507, 507)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(325, 325, 325))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
int cot;
    private void Loading(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_Loading
        // TODO add your handling code here:
        TableModel model;
        TableModel model2;
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            model = common.loadPhong();
            cot = model.getRowCount();
            
            if (model != null) {
                String[] bang = new String[model.getRowCount()];
                for (int i = 0; i < model.getRowCount(); i++) {
                    bang[i] = model.getValueAt(i, 1).toString();
                }
                int n = (model.getRowCount() / 4) + 1;
                int t = 0;
                for (int i = 0; i < tblPhong.getRowCount(); i++) {
                    for (int j = 0; j < tblPhong.getColumnCount(); j++) {
                        if (t < bang.length) {
                            tblPhong.setValueAt(bang[t], i, j);
                            tblPhong.getColumnModel().getColumn(j).setCellRenderer(new CustomRenderer());
                            t++;
                        } else {
                            tblPhong.setValueAt("", i, j);
                        }
                    }

                }
            }
            this.tblPhong.setRowSelectionInterval(0, 0);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(rootPane, "Kết nối Server thất bại ");
        }


    }//GEN-LAST:event_Loading
    private void kiemtraphong(int idphong) {
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            TableModel x = common.kiemtraphongtrong(idphong);
            if (x != null) {
                int y = Integer.parseInt(String.valueOf(x.getValueAt(0, 0)));
                if (y == 0) {
                    btnNhanPhong.setEnabled(true);
                    btnThemDV.setEnabled(false);
                    btnSuaDV.setEnabled(false);
                    btnXoaDV.setEnabled(false);
                    btnLuuDV.setEnabled(false);
                    cobTenDV.setEnabled(false);
                    txtSoLuong.setEnabled(false);
                    btnXuatHoaDon.setEnabled(false);
                } else {
                    btnNhanPhong.setEnabled(false);
                    btnThemDV.setEnabled(true);
                    btnSuaDV.setEnabled(true);
                    btnXoaDV.setEnabled(true);
                    btnLuuDV.setEnabled(false);
                    cobTenDV.setEnabled(false);
                    txtSoLuong.setEnabled(false);
                    btnXuatHoaDon.setEnabled(true);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private int tinhtiendv(int idphong) {
        int tien = 0;
        try {
            // ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            TableModel x = common.tinhtiendichvu(idphong);
            tien = Integer.parseInt(String.valueOf(x.getValueAt(0, 0)));
        } catch (Exception e) {
            tien = 0;
        }
        return tien;
    }

    private int tinhtienphong(int idphong) {
        int tien = 0;
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            TableModel x = common.tinhtienphong(idphong);
            tien = Integer.parseInt(String.valueOf(x.getValueAt(0, 0)));
        } catch (Exception e) {
            tien = 0;
        }
        return tien;
    }
    private void Clickbang(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Clickbang
    }//GEN-LAST:event_Clickbang
    private void enableButton(boolean b) {
        txtTenphong.setEnabled(b);
        txtVitri.setEnabled(b);
        cbbLoaiphong.setEnabled(b);
        btnThem.setEnabled(!b);
        btnSua.setEnabled(!b);
        btnXoa.setEnabled(!b);
        btnLuu.setEnabled(b);
        tblPhong.setEnabled(!b);
    }
    boolean luuthemphong = false;
    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
        // TODO add your handling code here:
        enableButton(true);
        txtMaphong.setText(null);
        txtTenphong.setText(null);
        txtVitri.setText(null);
        txtGiaphong.setText(null);
        fillComboboxLoaiphong();
        cbbLoaiphong.setEnabled(true);
        txtDonvitinh.setText(null);
        txtTenphong.requestFocus();
        luuthemphong = true;
    }//GEN-LAST:event_btnThemActionPerformed

    private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
        enableButton(true);
        fillComboboxLoaiphong();
        cbbLoaiphong.setEnabled(true);
        txtTenphong.requestFocus();
        luuthemphong = false;
    }//GEN-LAST:event_btnSuaActionPerformed

    private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
        try {
            int q = JOptionPane.showOptionDialog(this, "Bạn có chắn chắn xóa phòng này không?", "Thông báo", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
            if (q == 0) {

                int idp = Integer.parseInt(txtMaphong.getText());
                ReadXML read = new ReadXML();
                Registry registry = LocateRegistry.getRegistry(read.getInfo("ipServer"), Integer.parseInt(read.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                boolean t = common.DeletePhong(idp);
                if (t) {
                    JOptionPane.showMessageDialog(this, "Xóa phòng thành công", "Thông báo", WIDTH);
                    btnHuyActionPerformed(null);
                    enableButton(false);
                } else {
                    JOptionPane.showMessageDialog(this, "Xóa phòng không thành công", "Thông báo", WIDTH);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnXoaActionPerformed

    private void btnSuaDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaDVActionPerformed
        themdv = false;
        btnThemDV.setEnabled(false);
        btnSuaDV.setEnabled(false);
        btnXoaDV.setEnabled(false);
        btnLuuDV.setEnabled(true);
        cobTenDV.setEnabled(true);
        txtSoLuong.setEnabled(true);
    }//GEN-LAST:event_btnSuaDVActionPerformed

    private void tblPhongMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPhongMouseClicked
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            TableModel tb = common.LoadThongTinPhong(tblPhong.getValueAt(tblPhong.getSelectedRow(), tblPhong.getSelectedColumn()).toString());
            txtMaphong.setText(String.valueOf(tb.getValueAt(0, 0)));
            id_phong = Integer.parseInt(String.valueOf(tb.getValueAt(0, 0)));
            maphong.setIdphong(id_phong);
            txtTenphong.setText(String.valueOf(tb.getValueAt(0, 1)));
            maphong.setTenphong(String.valueOf(txtTenphong.getText()));
            txtVitri.setText(String.valueOf(tb.getValueAt(0, 2)));
            Vector<Loaiphong> model2 = new Vector<Loaiphong>();  // khai báo vector đón dữ liệu từ server rả về                          
            model2 = common.cbbphong(tb.getValueAt(0, 3).toString());
            if (model2 != null) {
                DefaultComboBoxModel defaultComboBoxMode2 = new javax.swing.DefaultComboBoxModel(model2);//model là  Vector<ParentRole> model = new Vector<ParentRole>();
                cbbLoaiphong.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
                cbbLoaiphong.setModel(defaultComboBoxMode2);
                cbbLoaiphong.setRenderer(new Phong_Quanly.ItemLoaiphong());
            }
            txtGiaphong.setText(String.valueOf(tb.getValueAt(0, 4)));
            txtDonvitinh.setText(String.valueOf(tb.getValueAt(0, 5)));
            loadTbDichVu(Integer.parseInt(txtMaphong.getText().toString()));
        } catch (Exception e) {
        }
    }//GEN-LAST:event_tblPhongMouseClicked

    private void btnHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHuyActionPerformed
        Loading(null);
        enableButton(false);
    }//GEN-LAST:event_btnHuyActionPerformed
    private void loadTbDichVu(int idphong) {
        try {
            //ReadXML read = new ReadXML();
            Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
            vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
            TableModel tb = common.loadsudung(idphong);
            if (tb != null) {
                tblDichVu.setModel(tb);
                kiemtraphong(idphong);
                lbTienDV.setText(String.valueOf(tinhtiendv(idphong)));
                lbTienPhong.setText(String.valueOf(tinhtienphong(idphong)));
                int thanhtien = tinhtiendv(idphong) + tinhtienphong(idphong);
                lbThanhTien.setText(String.valueOf(thanhtien));
                TableModel hoten = common.LoadTenKH(idphong);
                if (hoten.getRowCount() > 0) {
                    lbHoTen.setText(String.valueOf(hoten.getValueAt(0, 0)));
                    lbSDT.setText(String.valueOf(hoten.getValueAt(0, 1)));
                    lbNgayNhan.setText(String.valueOf(hoten.getValueAt(0, 4)));
                    lbNgayTra.setText(String.valueOf(hoten.getValueAt(0, 5)));
                } else {
                    lbHoTen.setText("");
                    lbSDT.setText("");
                    lbNgayNhan.setText("");
                    lbNgayTra.setText("");
                }
            } else {
                lbHoTen.setText("");
                lbSDT.setText("");
                lbNgayNhan.setText("");
                lbNgayTra.setText("");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void btnNhanPhongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNhanPhongActionPerformed
        Phong_NhanPhong nhanphong = new Phong_NhanPhong();
        nhanphong.setVisible(true);

    }//GEN-LAST:event_btnNhanPhongActionPerformed

    private void btnXoaDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaDVActionPerformed
        int i = JOptionPane.showConfirmDialog(this, "Bạn có muốn xóa dữ liệu này không?", "Cảnh Báo", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (i == 0) {
            try {
                JOptionPane.showMessageDialog(rootPane, id);
                //ReadXML read = new ReadXML();
                Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                boolean x = common.DeleteSuDungDV(id);
                if (x) {
                    JOptionPane.showMessageDialog(rootPane, "Xóa thành cmn công");
                    loadTbDichVu(id_phong);
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Xóa không thành công");
                    loadTbDichVu(id_phong);
                }

            } catch (Exception e) {
            }
        }
    }//GEN-LAST:event_btnXoaDVActionPerformed

    private void txtMaphongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMaphongActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtMaphongActionPerformed

    private void btnThemDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemDVActionPerformed
        themdv = true;
        btnThemDV.setEnabled(false);
        btnSuaDV.setEnabled(false);
        btnXoaDV.setEnabled(false);
        btnLuuDV.setEnabled(true);
        cobTenDV.setEnabled(true);
        txtSoLuong.setEnabled(true);

    }//GEN-LAST:event_btnThemDVActionPerformed

    private void btnLuuDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLuuDVActionPerformed
        DichVu dv = (DichVu) cobTenDV.getSelectedItem();
        int iddv = dv.getMadv();
        int soluong = 0;
        if (txtSoLuong.getText().equals("") || Integer.parseInt(txtSoLuong.getText()) < 0) {
            soluong = 0;
        } else {
            soluong = Integer.parseInt(txtSoLuong.getText());
        }
        if (themdv == true) {
            //them
            try {
                //ReadXML read = new ReadXML();
                Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                boolean x = common.insertSudungDV(id_phong, iddv, soluong);
                if (x) {
                    JOptionPane.showMessageDialog(rootPane, "Đã thêm");
                    loadTbDichVu(id_phong);
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Không thể thêm");
                }
            } catch (Exception e) {
            }
        } else {
            try {
                int row = tblDichVu.getSelectedRow();
                //ReadXML read = new ReadXML();
                Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                boolean x = common.updateSudungDV(id, iddv, soluong);
                if (x) {
                    JOptionPane.showMessageDialog(rootPane, "Cập nhật thành công");
                    loadTbDichVu(id_phong);
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Cập nhật không thành công");
                    loadTbDichVu(id_phong);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
    }//GEN-LAST:event_btnLuuDVActionPerformed

    private void tblDichVuMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDichVuMousePressed
        int index = tblDichVu.getSelectedRow();
        id = Integer.parseInt(String.valueOf(tblDichVu.getValueAt(index, 0)));
    }//GEN-LAST:event_tblDichVuMousePressed

    private void btnLuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLuuActionPerformed
        // TODO add your handling code here:
        String tenP = txtTenphong.getText();
        String vitri = txtVitri.getText();

        Loaiphong lphong = (Loaiphong) cbbLoaiphong.getSelectedItem();
        int lp = lphong.getMadv();
        if (tenP.equals("") || vitri.equals("")) {
            JOptionPane.showMessageDialog(this, "Bạn chưa nhập đủ thông tin", "Thông báo", WIDTH);
        } else if (luuthemphong) {

            try {
                //ReadXML read = new ReadXML();
                Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                boolean t = common.insertPhong(tenP, vitri, lp);
                if (t) {
                    JOptionPane.showMessageDialog(this, "Thêm phòng thành công", "Thông báo", WIDTH);
                    Loading(null);
                    enableButton(false);

                } else {
                    JOptionPane.showMessageDialog(this, "Thêm phòng không thành công", "Thông báo", WIDTH);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (!luuthemphong) {
            try {
                int idp = Integer.parseInt(txtMaphong.getText());
                ReadXML read = new ReadXML();
                Registry registry = LocateRegistry.getRegistry(read.getInfo("ipServer"), Integer.parseInt(read.getInfo("portserver")));
                vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                boolean t = common.updatePhong(idp, tenP, vitri, lp);
                if (t) {
                    JOptionPane.showMessageDialog(this, "Sữa phòng thành công", "Thông báo", WIDTH);
                    Loading(null);
                    enableButton(false);
                    lbHoTen.setText("");
                    lbSDT.setText("");
                    lbNgayNhan.setText("");
                    lbNgayTra.setText("");
                } else {
                    JOptionPane.showMessageDialog(this, "Sữa phòng không thành công", "Thông báo", WIDTH);
                    Loading(null);
                    enableButton(false);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_btnLuuActionPerformed

    private void btnXuatHoaDonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXuatHoaDonActionPerformed
        int i = JOptionPane.showConfirmDialog(this, "Bạn có muốn thanh toán cho khách hàng này?", "Cảnh Báo", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (i == 0) {

            String link = "src\\vn\\edu\\vttu\\phong\\report_Hoadon.jrxml";
            try {
                //Tạo kết nối đến Mysql
                Class.forName("com.mysql.jdbc.Driver");
                String database = "jdbc:mysql://" + thongtindb.getIp() + ":" + thongtindb.getPort() + "/" + thongtindb.getDb();
                String us = thongtindb.getU();
                String pa = thongtindb.getP();
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("TenKH", lbHoTen.getText());
                params.put("Tenphong", txtTenphong.getText());
                Loaiphong lphong = (Loaiphong) cbbLoaiphong.getSelectedItem();
                params.put("Loaiphong", lphong.getTendv());
                params.put("Giaphong", Integer.parseInt(txtGiaphong.getText()));
                params.put("Maphong", txtMaphong.getText());
                params.put("Songay",1);
                params.put("TienP", Integer.parseInt(lbTienPhong.getText()));
                params.put("TienDV", Integer.parseInt(lbTienDV.getText()));
                params.put("Tongtien", Integer.parseInt(lbThanhTien.getText()));
                params.put("Ngaythue", lbNgayNhan.getText());
                params.put("Ngaytra", lbNgayTra.getText());
                params.put("Nhanvien", dangNhap.HotenDN);
                Connection conn = (Connection) DriverManager.getConnection(database, us, pa);
                // tạo JasperReport
                JasperReport jr = JasperCompileManager.compileReport(link);
                //tạo JasperPrint
                JasperPrint jp = JasperFillManager.fillReport(jr, params, conn);
                //Tạo JasperViewer
                JasperViewer jv = new JasperViewer(jp, false);
                jv.setVisible(true);

                try {
                    //ReadXML read = new ReadXML();
                    Registry registry = LocateRegistry.getRegistry(read1.getInfo("ipServer"), Integer.parseInt(read1.getInfo("portserver")));
                    vn.edu.vttu.RMI_Interface common = (vn.edu.vttu.RMI_Interface) registry.lookup("ServerKhachSan");
                    boolean x = common.traphong(id_phong);
                    if (x) {
                        //JOptionPane.showMessageDialog(rootPane, "Thành công");
                        Loading(null);
                    } else {
                        //JOptionPane.showMessageDialog(rootPane, "Lỗi, vui lòng thử lại");
                        Loading(null);
                    }
                } catch (Exception e) {
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_btnXuatHoaDonActionPerformed

    private void txtSoLuongKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSoLuongKeyTyped
        int key = evt.getKeyChar();
        String st = txtSoLuong.getText();
        String stTest = "0123456789";
        if (key != evt.VK_BACK_SPACE
                && key != evt.VK_DELETE
                && key != evt.VK_ENTER) {
            int flag = 0;
            if (stTest.indexOf(evt.getKeyChar()) == -1) {
                flag++;
                JOptionPane.showMessageDialog(this, "Chỉ được nhập số");
            }
            if (flag > 0) {
                evt.consume();
            }
        }
    }//GEN-LAST:event_txtSoLuongKeyTyped

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        QuanLy_DichVu qldv = new QuanLy_DichVu();
        qldv.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        QuanLy_LoaiPhong qllp = new QuanLy_LoaiPhong();
        qllp.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Phong_Quanly.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Phong_Quanly.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Phong_Quanly.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Phong_Quanly.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Phong_Quanly qlp = new Phong_Quanly();
                qlp.setVisible(true);
                qlp.setExtendedState(qlp.getExtendedState() | JFrame.MAXIMIZED_BOTH);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnHuy;
    private javax.swing.JButton btnLuu;
    private javax.swing.JButton btnLuuDV;
    private javax.swing.JButton btnNhanPhong;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnSuaDV;
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnThemDV;
    private javax.swing.JButton btnXoa;
    private javax.swing.JButton btnXoaDV;
    private javax.swing.JButton btnXuatHoaDon;
    private javax.swing.JComboBox cbbLoaiphong;
    private javax.swing.JComboBox cobTenDV;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbHoTen;
    private javax.swing.JLabel lbNgayNhan;
    private javax.swing.JLabel lbNgayTra;
    private javax.swing.JLabel lbSDT;
    private javax.swing.JLabel lbThanhTien;
    private javax.swing.JLabel lbTienDV;
    private javax.swing.JLabel lbTienPhong;
    private javax.swing.JTable tblDichVu;
    private javax.swing.JTable tblPhong;
    private javax.swing.JTextField txtDonvitinh;
    private javax.swing.JTextField txtGiaphong;
    private javax.swing.JTextField txtMaphong;
    private javax.swing.JTextField txtSoLuong;
    private javax.swing.JTextField txtTenphong;
    private javax.swing.JTextField txtVitri;
    // End of variables declaration//GEN-END:variables
}
